package cn.ekgc.hbase;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.*;
import org.apache.hadoop.hbase.util.Bytes;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class PutListDemo {
    static Scanner input = new Scanner(System.in);
    public static void main(String[] args) throws Exception {
        Configuration config = HBaseConfiguration.create(); //获取链接信息
        //创建表
        //创建链接
        try (Connection connection = ConnectionFactory.createConnection(config)) {
            Admin admin = connection.getAdmin();

            System.out.println("input row eg: row-0002,personalinfo:nickname,wangwu | input !bye exit");
            List<Put> list = new ArrayList<>();
            while (true){
                String line = input.nextLine();
                if("!bye".equals(line)){
                    break;
                }
                String[] row=line.split(",");
                String[] familyAndQualifier=row[1].split(":");
                Put put = new Put(Bytes.toBytes(row[0]));
                put.addColumn(Bytes.toBytes(familyAndQualifier[0]),Bytes.toBytes(familyAndQualifier[1]),Bytes.toBytes(row[2]));
                list.add(put);

            }
            HTable table  = (HTable) connection.getTable(TableName.valueOf("gamer"));
            System.out.println("doing put........");
            table.put(list);
            System.out.println(" Done.");

        }
    }
}
